package net.hn.hnms.biz.support.service.impl;

import net.hn.hnms.biz.support.domain.SupportNowPo;
import net.hn.hnms.biz.support.domain.SupportdataNowPo;
import net.hn.hnms.biz.support.domain.vo.MonitorEchartVo;
import net.hn.hnms.biz.support.domain.vo.RoofStatisticalInformationVo;
import net.hn.hnms.biz.support.mapper.AnchordataNowMapper;
import net.hn.hnms.biz.support.service.RoofService;
import net.hn.hnms.biz.support.service.RoofSupprotService;
import net.hn.hnms.biz.support.service.SupportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName: RoofSupprotServiceImpl
 * @Description 顶板监测
 * @Author 王龙
 * @Date 2022-10-17
 * @Version 0.1
 */
@Service
public class RoofSupprotServiceImpl implements RoofSupprotService {

    //cjdy
    @Resource
    private RoofService roofService;
    @Resource
    private SupportService supportService;


    @Resource
    private AnchordataNowMapper anchordataNowMapper;

    /**
     * 统计信息
     *
     * @return
     */
    @Override
    public RoofStatisticalInformationVo statisticalInformation(String mineCode) {
        //统计信息返回数据
        RoofStatisticalInformationVo roofStatisticalInformationVo = new RoofStatisticalInformationVo();
        //最大支架阻力
        SupportNowPo supportNowPo = supportService.selectSupportNowPoOne(mineCode);
        roofStatisticalInformationVo.setMaxHolderResistance(supportNowPo.getPointValue());


        //最大离层量  获取实时表的所有数据 离层量= 深基点-浅基点
        roofStatisticalInformationVo.setMaxAbscission(roofService.getAnchordataNowListValue(mineCode));


        //最大锚杆应力

        roofStatisticalInformationVo.setMaxRockBolt(anchordataNowMapper.maxValue("锚杆"));
        //最大锚索应力
        roofStatisticalInformationVo.setMaxAnchorCable(anchordataNowMapper.maxValue("锚索"));
        return roofStatisticalInformationVo;
    }

    /**
     * cjdy-支架实时数据
     * @param mineCode
     * @return
     */
    @Override
    public MonitorEchartVo monitorEchart(String mineCode) {
        //获取cjdy支架now表实时数据
        List<SupportdataNowPo> supportdataNowPos= roofService.distinctSupportdataNow(mineCode);
        //排序
        Collections.sort(supportdataNowPos);

        if (supportdataNowPos.isEmpty()) {
            MonitorEchartVo monitorEchartVo = new MonitorEchartVo();
            monitorEchartVo.setValue(new ArrayList<>());
            monitorEchartVo.setNumber(new ArrayList<>());
            return monitorEchartVo;
        }

        MonitorEchartVo monitorEchartVo = new MonitorEchartVo();
        //柱子序号
        List<String> number = new ArrayList<>();
        //柱子值
        List<Float> value = new ArrayList<>();
//        //日期
//        List<Date> date = new ArrayList<>();
        for (SupportdataNowPo supportdataNowPo : supportdataNowPos) {
            //获取柱子位置
            number.add(supportdataNowPo.getPointLocation());
            //获取柱子值
            value.add(supportdataNowPo.getPointValue().floatValue());
//            //日期
//            date.add(supportdataNowPo.getDataTime());
        }
        monitorEchartVo.setValue(value);
        monitorEchartVo.setNumber(number);
        return monitorEchartVo;
    }

    /**
     * 支架实时
     * @param mineCode
     * @return
     */
    @Override
    public List<SupportdataNowPo> selectListSuportNow(String mineCode) {
        List<SupportdataNowPo> supportdataNowPos= roofService.distinctSupportdataNow(mineCode);
        Collections.sort(supportdataNowPos);
        if (supportdataNowPos.isEmpty()) {
            return new ArrayList<>();
        }

        return supportdataNowPos;
    }

}
